﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.CMS.Content;
using MethodWorx.CMS.Web;

namespace MethodWorx.CMS.TemplateLanguage
{
    public class PageNameParser : IParser
    {
        #region IParser Members

        public string[] Parameters { get { return new string[] { }; } }

        public object Parse(CmsRequestContext context, IEnumerable<object> stack, Dictionary<string, object> parameters)
        {
            //
            //  look up the stack for the first page
            var page = stack.OfType<Page>().FirstOrDefault();
            if (page == null)
                throw new Exception(" No page on the stack");

            //  return name from the stack
            return page.Name;
        }

        public string Name
        {
            get { return "name"; }
        }

        public string Namespace
        {
            get { return "page"; }
        }

        #endregion
    }
}
